{
 "cells": [
  {
   "attachments": {},
   "cell_type": "markdown",
   "id": "3ea7576e-1f54-4983-a8d1-1f6c0e2165de",
   "metadata": {},
   "source": [
    "# Quickstart\n",
    "\n",
    "These instructions will help you create a report in <1 minute. We will build a simple HTML report using Python based on the [Iris dataset](https://en.wikipedia.org/wiki/Iris_flower_data_set).\n",
    "\n",
    "## Installation\n",
    "\n",
    "First, install Datapane using `pip` or `conda`. Check out our [installation page](/install-datapane/) for installation options. \n",
    "\n",
    "!!! note\n",
    "    You can also download this Quickstart as a [Jupyter Notebook](https://raw.githubusercontent.com/datapane/datapane/main/public-docs/docs/quickstart.ipynb){:download=quickstart.ipynb}.\n",
    "\n",
    "\n",
    "```python\n",
    "pip3 install -U datapane\n",
    "```"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "id": "8e65f2fe-82a3-48f3-8f9e-b61c3e76bcb8",
   "metadata": {},
   "source": [
    "## Setting things up"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3e15ebac-8fae-4b37-a1fc-627e43420109",
   "metadata": {},
   "outputs": [],
   "source": [
    "import altair as alt\n",
    "import datapane as dp\n",
    "from vega_datasets import data"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "id": "41888ecb-53a5-4b78-8027-b026acc486b4",
   "metadata": {},
   "source": [
    "We've imported `datapane`, the popular visualization library `altair`, and `vega_datasets` which contains some sample datasets.\n",
    "\n",
    "Let's load the Iris dataset and get a list of the features."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7d284782-3f15-4f67-aecc-9961285ce671",
   "metadata": {},
   "outputs": [],
   "source": [
    "df = data.iris()\n",
    "columns = list(df.columns)\n",
    "print(columns)"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "id": "bfc4a96c",
   "metadata": {},
   "source": [
    "## Blocks\n",
    "\n",
    "Your report is comprised of _Blocks_, which are Python objects that wrap around common objects such as datasets, plots, and other blocks. There are display blocks, such as _Plot_ or _DataTable_, and layout blocks, such as _Select_ and _Group_.\n",
    "\n",
    "Having loaded our DataFrame above and with knowledge of our column names, we first create a simple scatterplot using the Altair plotting library. \n",
    "\n",
    "We then build a simple set of blocks which presents two tabs: one with our plot, and one with our DataFrame."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7ba6a3d5",
   "metadata": {},
   "outputs": [],
   "source": [
    "fig = (\n",
    "    alt.Chart(df)\n",
    "    .mark_point()\n",
    "    .encode(x=alt.X(\"sepalLength\", scale=alt.Scale(zero=False)), \n",
    "            y=alt.X(\"sepalWidth\", scale=alt.Scale(zero=False)),\n",
    "            color=\"species\")\n",
    ")\n",
    "\n",
    "view = dp.Select(dp.Plot(fig, label=\"Plot\"), dp.DataTable(df, label=\"Data\"))\n",
    "view"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "id": "64dc4fa3",
   "metadata": {},
   "source": [
    "## Reports\n",
    "\n",
    "Once we have a view, we can save it as an HTML report to share.\n",
    "\n",
    "Let's save it as a report and [open it in a new window](./quickstart_report.html){:target=_blank}."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "58d6cf64",
   "metadata": {},
   "outputs": [],
   "source": [
    "dp.save_report(view, \"quickstart_report.html\", open=True)"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "id": "ea646651-32c5-425b-8aeb-d34a7cdbaf30",
   "metadata": {},
   "source": [
    "## Sharing your report\n",
    "\n",
    "That's it! As Datapane has created a standalone HTML file, you can now share this Slack or email without deploying any code or configuring a backend server. "
   ]
  }
 ],
 "metadata": {
  "language_info": {
   "name": "python"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
